<template>
    <div class="xl-table">
        <xlUntil text="部门用户" @addForm="addForm" :untilVisible="false" :queryParam="queryParam" @searchKeyWord="searchKeyWord" :searchColumns="columns"  @delBatch="delBatch" :export-xls-data="columns" :export-xls-url="url.exportXlsUrl">
            <a-select v-model="queryParam.loginUserStatus" placeholder="选择用户状态" showSearch allowClear  style="margin-right: 16px;width: 200px;">
                <a-select-option value="1">
                    正常
                </a-select-option>
                <a-select-option value="99">
                    冻结
                </a-select-option>
            </a-select>
        </xlUntil>
        <div class="xl-table-content">
            <xlTable
                    :columns="columns"
                    :dataSource="data"
                    rowKey="id"
                    :pagination="pagination"
                    :loading="loading"
                    @change="handleTableChange"
                    bordered
                    :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}">
                >
                <template v-slot:action="scope">
                    <a @click="editForm(scope.record)">编辑</a>
                    <a-divider type="vertical"/>
                    <a-dropdown>
                        <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
                        <a-menu slot="overlay">
                            <a-menu-item @click="seeForm(scope.record)">
                                <a>查看</a>
                            </a-menu-item>
                            <a-menu-item @click="setAuth(scope.record)">
                                <a>赋权</a>
                            </a-menu-item>
                            <a-menu-item @click="reset(scope.record.loginUserCode)">
                                <a>重置</a>
                            </a-menu-item>
                            <a-menu-item @click="setStatus(scope.record)">
                                <a>{{scope.record.loginUserStatus == 1?'冻结':'解冻'}}</a>
                            </a-menu-item>
                            <a-menu-item>
                                <a-popconfirm title="确定删除吗?" @confirm="() => delForm(scope.record.id)">
                                    <a>删除</a>
                                </a-popconfirm>
                            </a-menu-item>
                        </a-menu>
                    </a-dropdown>
                </template>
            </xlTable>
        </div>
        <xlForm ref="xlForm" @handleOk="handleOk"></xlForm>
        <seeForm ref="seeForm"></seeForm>
        <role ref="auth"></role>
    </div>
</template>

<script>

    import xlMixin from '../../../components/mixin'
    import xlForm from './model/form'
    import role from './model/role'

    import {password_reset, userFrozen, userThaw} from "../../../assets/api";
    
    export default {
        name: "index",
        mixins:[xlMixin],
        data(){
            return{
                columns: [
                    {
                        title: '编号',
                        key: 'rowIndex',
                        width: '150px',
                        fixed: 'left',
                        align: "center",
                        customRender: function (t, r, index) {
                            return parseInt(index) + 1;
                        }
                    },
                    {
                        title: '用户名',
                        align: "center",
                        fixed: 'left',
                        dataIndex: 'userName',
                        type: 'input'
                    },
                    {
                        title: '登陆名',
                        align: "center",
                        dataIndex: 'loginUserName',
                        type: 'input'
                    },
                    {
                        title: '用户密码',
                        align: "center",
                        dataIndex: 'loginPassword',
                        type: 'input.password',
                        tableVisible:true,
                        tableHide:true
                    },
                    {
                        title: '部门',
                        align: "center",
                        dataIndex: 'departmentName',
                        type: 'input'
                    },
                    {
                        title: '用户编号',
                        align: "center",
                        formVisible:true,
                        type: 'input',
                        dataIndex: 'loginUserCode',
                    },
                    {
                        title: '是否内置',
                        align: "center",
                        dataIndex: 'builtIn',
                        type: 'radio',
                        typeData: [
                            {
                                dataValue:true,
                                dataName:'是'
                            },
                            {
                                dataValue:false,
                                dataName:'否'
                            }
                        ],
                    },
                    {
                        title: '登陆IP',
                        align: "center",
                        type: 'input',
                        formVisible:true,
                        dataIndex: 'lastLoginIpAddress'
                    },
                    {
                        title: '登陆时间',
                        align: "center",
                        dataIndex: 'lastLoginDateTime',
                        type:'date',
                        formVisible:true,
                        typeData:'dateTime'
                    },
                    {
                        title: '用户状态',
                        align: "center",
                        dataIndex: 'loginUserStatus',
                        type: 'radio',
                        typeData: [
                            {
                                dataValue:'1',
                                dataName:'正常'
                            },
                            {
                                dataValue:'99',
                                dataName:'冻结'
                            }
                        ]
                    },
                    {
                        title: '登陆错误次数',
                        align: "center",
                        formVisible:true,
                        type: 'input',
                        dataIndex: 'loginErrorCount',
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align: "center",
                        fixed: 'right',
                        scopedSlots: {customRender: 'action'},
                    }
                ],
                url: {
                    list: "/system/api/system/login/user/page/_list",
                    add: '/system/api/system/login/user/save',
                    edit: '/system/api/system/login/user/save',
                    delete: "/system/api/system/login/user/_remove",
                    deleteBatch: "/system/api/system/login/user/_remove",
                    exportXlsUrl: "/ndo/api/new/dev/org/export/team/members",
                    importExcelUrl: "/person/project/upload/cjjn"
                }
            }
        },
        components:{
            xlForm,
            role
        },
        created(){
            this.formatMerge()
            this.pageOnload()
        },
        methods:{
            reset(value){
                password_reset({
                    param:value
                })
                    .then(result=>{
                        this.$message.success('操作成功')
                    })
            },
            setStatus(value){
                this.$confirm({
                    title: '提示',
                    content: '确定'+(value.loginUserStatus == 1?'冻结':'解冻')+'吗？',
                    onOk: () => {
                        if(value.loginUserStatus == 1){
                            userFrozen({
                                param:value.loginUserCode
                            })
                                .then(result=>{
                                    this.$message.success('操作成功')
                                    value.loginUserStatus = 99
                                })
                        }
                        if(value.loginUserStatus == 99){
                            userThaw({
                                param:value.loginUserCode
                            })
                                .then(result=>{
                                    this.$message.success('操作成功')
                                    value.loginUserStatus = 1
                                })
                        }
                    }
                })

            },
            setAuth(data){
                this.$refs.auth.formatValue(data)
                this.$refs.auth.visible = true
            }
        }
    }
</script>

<style scoped lang="less">
    .xl-table{
        .xl-table-content{
            padding: 16px;
        }
    }
</style>
